#include "multiget.h"
#include "ui_multiget.h"
#include <QUrl>
#include <QtNetwork/QNetworkReply>
#include <qdebug.h>
#include <QFile>

MultiGet::MultiGet(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MultiGet)
    {
    ui->setupUi(this);
    }
void MultiGet::descarga(QUrl url)
{
QNetworkRequest request(url);
request.setRawHeader("Range","bytes=14405480320-");
QNetworkReply *reply = manager.get(request);
connect(reply,SIGNAL(downloadProgress(qint64,qint64)),SLOT(progreso(qint64,qint64)));
connect(reply,SIGNAL(readyRead()),SLOT(leeDatos()));
connect(reply,SIGNAL(finished()),SLOT(fin()));
}

void MultiGet::leeDatos()
{
QNetworkReply *reply =(QNetworkReply*)this->sender();
reply->readAll();
qDebug() << "datos\n";
}

void MultiGet::progreso(qint64 n, qint64 t)
{
qDebug() << n << t << "\n";
}

void MultiGet::fin()
{
QFile p1("p.txt");
QFile p2("p.txt");
p1.open(QIODevice::ReadWrite);
p2.open(QIODevice::ReadWrite);
p1.seek(0);
p2.seek(2);
p2.write("23");
p1.write("01");
p1.close();
p2.close();
}

MultiGet::~MultiGet()
    {
    delete ui;
    }
